/*************************************************
 * 
 * Copyright by Bruno Eberhard
 * 
 * Created on 31.07.2005
 *
 *************************************************/
package fightplan.views.tables;

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;

import fightplan.business.CategoryType;
import fightplan.ui.BeanPropertyListCellRenderer;

@SuppressWarnings("serial")
public class CategoryTypeCellEditor extends DefaultCellEditor {

	public CategoryTypeCellEditor(CategoryType[] categoryTypes) {
		super(createComboBox(categoryTypes));
	}

	private static JComboBox createComboBox(CategoryType[] categoryTypes) {
		JComboBox comboBox = new JComboBox(categoryTypes);
		comboBox.setRenderer(new BeanPropertyListCellRenderer("name"));
		comboBox.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		comboBox.setEditable(false);
		return comboBox;
	}

	public Object getCellEditorValue() {
		Object o = ((JComboBox) getComponent()).getSelectedItem();
		if (o instanceof CategoryType) {
			return o;
		}
		return CategoryType.UNSET;
	}

}
